package com.tf.integrated.controller;

import com.alibaba.fastjson.JSONObject;
import com.ccssoft.m8.common.ccssoft.modules.util.EntityWrapperHandle;
import com.ccssoft.m8.common.web.BaseController;
import com.tf.integrated.entity.*;
import com.tf.integrated.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

/**
 * 查询预警详情
 * @author allen
 * @date: 2020年9月14日上午10:56:20
 */
@Api(value = "查询预警详细信息",description="SearchWarningDetailController")
@RestController
public class SearchWarningDetailController extends BaseController
{
    @Autowired
    private WarningresultvehicleinfoService<WarningresultvehicleinfoEntity> vehicleService;

    @Autowired
    private WarningresultpersonService<WarningresultpersonEntity> personService;

    @Autowired
    private WarningresulttricyclesinfoService<WarningresulttricyclesinfoEntity> tricycleService;

    @Autowired
    private WarningresultpedestriansinfoService<WarningresultpedestriansinfoEntity> pedestrianService;

    @Autowired
    private WarningresultbikesinfoService<WarningresultbikesinfoEntity> bikeService;

    @ApiOperation("查询预警详细信息")
    @GetMapping("/search/warning/detail")
    @CrossOrigin(origins = "*",maxAge = 86400)
    public JSONObject searchDataList(@RequestParam Map<String, Object> data) {
        JSONObject returnData=new JSONObject();
        if (data != null && data.size() > 0) {
            String host = (String) data.get("host");
            String chn = (String) data.get("chnId");
            String fullpicpath = (String) data.get("fullpicpath");
            String objpicpath = (String) data.get("objpicpath");
            String stype= (String) data.get("type");
            int type=0;
            if(isExist(stype)&&isInteger(stype)){
                type=Integer.parseInt(stype);
            }
            if(type>0&&isExist(fullpicpath)&&isExist(objpicpath)&&isExist(host)&&isExist(chn)){
                switch (type){
                    case 1:{
                        returnData=getTypeOne(host,chn,fullpicpath,objpicpath);
                        break;
                    }
                    case 2:{
                        returnData=getTypeTwo(host,chn,fullpicpath,objpicpath);
                        break;
                    }
                    case 3:{
                        returnData=getTypeThree(host,chn,fullpicpath,objpicpath);
                        break;
                    }
                    case 4:{
                        returnData=getTypeFour(host,chn,fullpicpath,objpicpath);
                        break;
                    }
                    case 5:{
                        returnData=getTypeFive(host,chn,fullpicpath,objpicpath);
                        break;
                    }
                }
            }
        }
        return returnData;
    }

    public JSONObject getTypeOne(String host,String chn,String fullpicpath,String objpicpath){
        JSONObject json = new JSONObject();
        EntityWrapperHandle<WarningresultvehicleinfoEntity> ew = new EntityWrapperHandle<WarningresultvehicleinfoEntity>();
        ew.eq("chn",chn);
        ew.eq("deviceid",host);
        ew.eq("fullpicpath",fullpicpath);
        ew.eq("objpicpath",objpicpath);
        List<WarningresultvehicleinfoEntity> list = vehicleService.selectList(ew);
        if(list!=null&&list.size()>0){
            WarningresultvehicleinfoEntity WarningresultvehicleinfoEntity = list.get(0);
            json.put("id", WarningresultvehicleinfoEntity.getId());
            json.put("CarType", WarningresultvehicleinfoEntity.getCartype());
            json.put("Chn", WarningresultvehicleinfoEntity.getChn());
            json.put("CoDriver", WarningresultvehicleinfoEntity.getCodriver());
            json.put("CoNoBelt", WarningresultvehicleinfoEntity.getConobelt());
            json.put("Color", WarningresultvehicleinfoEntity.getColor());
            json.put("DriveWay", WarningresultvehicleinfoEntity.getDriveway());
            json.put("Drop", WarningresultvehicleinfoEntity.getDrop());
            json.put("FullPicPath", WarningresultvehicleinfoEntity.getFullpicpath());
            json.put("HasCall", WarningresultvehicleinfoEntity.getHascall());
            json.put("HasCrash", WarningresultvehicleinfoEntity.getHascrash());
            json.put("HasRack", WarningresultvehicleinfoEntity.getHasrack());
            json.put("HasSpareTire", WarningresultvehicleinfoEntity.getHassparetire());
            json.put("HasSunroof", WarningresultvehicleinfoEntity.getHassunroof());
            json.put("IsDanger", WarningresultvehicleinfoEntity.getIsdanger());
            json.put("IsSlag", WarningresultvehicleinfoEntity.getIsslag());
            json.put("MainNoBelt", WarningresultvehicleinfoEntity.getMainnobelt());
            json.put("MarkerNum", WarningresultvehicleinfoEntity.getMarkernum());
            json.put("ObjPicPath", WarningresultvehicleinfoEntity.getObjpicpath());
            json.put("Orientation", WarningresultvehicleinfoEntity.getOrientation());
            json.put("Paper", WarningresultvehicleinfoEntity.getPaper());
            json.put("PlateInfo", WarningresultvehicleinfoEntity.getPlateinfo());
            json.put("Rect", WarningresultvehicleinfoEntity.getRect());
            json.put("StyleName", WarningresultvehicleinfoEntity.getStylename());
            json.put("Time", WarningresultvehicleinfoEntity.getTime());
            json.put("Type", WarningresultvehicleinfoEntity.getType());
            json.put("DeviceId", WarningresultvehicleinfoEntity.getDeviceid());
        }
        return json;
    }

    public JSONObject getTypeTwo(String host,String chn,String fullpicpath,String objpicpath){
        JSONObject json = new JSONObject();
        EntityWrapperHandle<WarningresulttricyclesinfoEntity> ew = new EntityWrapperHandle<WarningresulttricyclesinfoEntity>();
        ew.eq("chn",chn);
        ew.eq("deviceid",host);
        ew.eq("fullpicpath",fullpicpath);
        ew.eq("objpicpath",objpicpath);
        List<WarningresulttricyclesinfoEntity> list = tricycleService.selectList(ew);
        if(list!=null&&list.size()>0) {
            WarningresulttricyclesinfoEntity WarningresulttricyclesinfoEntity = list.get(0);
            json.put("id", WarningresulttricyclesinfoEntity.getId());
            json.put("Chn", WarningresulttricyclesinfoEntity.getChn());
            json.put("Convertible", WarningresulttricyclesinfoEntity.getConvertible());
            json.put("DriveWay", WarningresulttricyclesinfoEntity.getDriveway());
            json.put("FullPicPath", WarningresulttricyclesinfoEntity.getFullpicpath());
            json.put("Manned", WarningresulttricyclesinfoEntity.getManned());
            json.put("ObjPicPath", WarningresulttricyclesinfoEntity.getObjpicpath());
            json.put("Rect", WarningresulttricyclesinfoEntity.getRect());
            json.put("RoofColor", WarningresulttricyclesinfoEntity.getRoofcolor());
            json.put("Time", WarningresulttricyclesinfoEntity.getTime());
            json.put("Type", WarningresulttricyclesinfoEntity.getType());
            json.put("DeviceId", WarningresulttricyclesinfoEntity.getDeviceid());
        }
        return json;
    }

    public JSONObject getTypeThree(String host,String chn,String fullpicpath,String objpicpath){
        JSONObject json = new JSONObject();
        EntityWrapperHandle<WarningresultpedestriansinfoEntity> ew = new EntityWrapperHandle<WarningresultpedestriansinfoEntity>();
        ew.eq("chn",chn);
        ew.eq("deviceid",host);
        ew.eq("fullpicpath",fullpicpath);
        ew.eq("objpicpath",objpicpath);
        List<WarningresultpedestriansinfoEntity> list = pedestrianService.selectList(ew);
        if(list!=null&&list.size()>0) {
            WarningresultpedestriansinfoEntity WarningresultpedestriansinfoEntity = list.get(0);
            json.put("id", WarningresultpedestriansinfoEntity.getId());
            json.put("Age", WarningresultpedestriansinfoEntity.getAge());
            json.put("Baby", WarningresultpedestriansinfoEntity.getBaby());
            json.put("Bag", WarningresultpedestriansinfoEntity.getBag());
            json.put("BottomColor", WarningresultpedestriansinfoEntity.getBottomcolor());
            json.put("BottomType", WarningresultpedestriansinfoEntity.getBottomtype());
            json.put("Chn", WarningresultpedestriansinfoEntity.getChn());
            json.put("DriveWay", WarningresultpedestriansinfoEntity.getDriveway());
            json.put("FullPicPath", WarningresultpedestriansinfoEntity.getFullpicpath());
            json.put("Glasses", WarningresultpedestriansinfoEntity.getGlasses());
            json.put("Hair", WarningresultpedestriansinfoEntity.getHair());
            json.put("Hat", WarningresultpedestriansinfoEntity.getHat());
            json.put("Knapsack", WarningresultpedestriansinfoEntity.getKnapsack());
            json.put("Mask", WarningresultpedestriansinfoEntity.getMask());
            json.put("MessengerBag", WarningresultpedestriansinfoEntity.getMessengerbag());
            json.put("ObjPicPath", WarningresultpedestriansinfoEntity.getObjpicpath());
            json.put("Orientation", WarningresultpedestriansinfoEntity.getOrientation());
            json.put("Rect", WarningresultpedestriansinfoEntity.getRect());
            json.put("Sex", WarningresultpedestriansinfoEntity.getSex());
            json.put("ShoulderBag", WarningresultpedestriansinfoEntity.getShoulderaag());
            json.put("Time", WarningresultpedestriansinfoEntity.getTime());
            json.put("Type", WarningresultpedestriansinfoEntity.getType());
            json.put("Umbrella", WarningresultpedestriansinfoEntity.getUmbrella());
            json.put("UpperColor", WarningresultpedestriansinfoEntity.getUppercolor());
            json.put("UpperTexture", WarningresultpedestriansinfoEntity.getUppertexture());
            json.put("UpperType", WarningresultpedestriansinfoEntity.getUppertype());
            json.put("DeviceId", WarningresultpedestriansinfoEntity.getDeviceid());
        }
        return json;
    }

    public JSONObject getTypeFour(String host,String chn,String fullpicpath,String objpicpath){
        JSONObject json = new JSONObject();
        EntityWrapperHandle<WarningresultbikesinfoEntity> ew = new EntityWrapperHandle<WarningresultbikesinfoEntity>();
        ew.eq("chn",chn);
        ew.eq("deviceid",host);
        ew.eq("fullpicpath",fullpicpath);
        ew.eq("objpicpath",objpicpath);
        List<WarningresultbikesinfoEntity> list = bikeService.selectList(ew);
        if(list!=null&&list.size()>0) {
            WarningresultbikesinfoEntity WarningresultbikesinfoEntity = list.get(0);
            json.put("id", WarningresultbikesinfoEntity.getId());
            json.put("Age", WarningresultbikesinfoEntity.getAge());
            json.put("Baby", WarningresultbikesinfoEntity.getBaby());
            json.put("Bag", WarningresultbikesinfoEntity.getBag());
            json.put("BottomColor", WarningresultbikesinfoEntity.getBottomcolor());
            json.put("BottomType", WarningresultbikesinfoEntity.getBottomtype());
            json.put("Chn", WarningresultbikesinfoEntity.getChn());
            json.put("DriveWay", WarningresultbikesinfoEntity.getDriveway());
            json.put("FullPicPath", WarningresultbikesinfoEntity.getFullpicpath());
            json.put("Glasses", WarningresultbikesinfoEntity.getGlasses());
            json.put("Hair", WarningresultbikesinfoEntity.getHair());
            json.put("Hat", WarningresultbikesinfoEntity.getHat());
            json.put("Knapsack", WarningresultbikesinfoEntity.getKnapsack());
            json.put("Mask", WarningresultbikesinfoEntity.getMask());
            json.put("MessengerBag", WarningresultbikesinfoEntity.getMessengerbag());
            json.put("ObjPicPath", WarningresultbikesinfoEntity.getObjpicpath());
            json.put("Orientation", WarningresultbikesinfoEntity.getOrientation());
            json.put("Rect", WarningresultbikesinfoEntity.getRect());
            json.put("Sex", WarningresultbikesinfoEntity.getSex());
            json.put("ShoulderBag", WarningresultbikesinfoEntity.getShoulderaag());
            json.put("Time", WarningresultbikesinfoEntity.getTime());
            json.put("Type", WarningresultbikesinfoEntity.getType());
            json.put("Umbrella", WarningresultbikesinfoEntity.getUmbrella());
            json.put("UpperColor", WarningresultbikesinfoEntity.getUppercolor());
            json.put("UpperTexture", WarningresultbikesinfoEntity.getUppertexture());
            json.put("UpperType", WarningresultbikesinfoEntity.getUppertype());
            json.put("DeviceId", WarningresultbikesinfoEntity.getDeviceid());
        }
        return json;
    }

    public JSONObject getTypeFive(String host,String chn,String fullpicpath,String objpicpath){
        JSONObject json = new JSONObject();
        EntityWrapperHandle<WarningresultpersonEntity> ew = new EntityWrapperHandle<WarningresultpersonEntity>();
        ew.eq("chn",chn);
        ew.eq("deviceid",host);
        ew.eq("fullpicpath",fullpicpath);
        ew.eq("objpicpath",objpicpath);
        List<WarningresultpersonEntity> list = personService.selectList(ew);
        if(list!=null&&list.size()>0) {
            WarningresultpersonEntity WarningresultpersonEntity = list.get(0);
            json.put("id", WarningresultpersonEntity.getId());
            json.put("Age", WarningresultpersonEntity.getAge());
            json.put("Chn", WarningresultpersonEntity.getChn());
            json.put("FullPicPath", WarningresultpersonEntity.getFullpicpath());
            json.put("Glasses", WarningresultpersonEntity.getGlasses());
            json.put("Hair", WarningresultpersonEntity.getHair());
            json.put("Hat", WarningresultpersonEntity.getHat());
            json.put("Mask", WarningresultpersonEntity.getMask());
            json.put("ObjPicPath", WarningresultpersonEntity.getObjpicpath());
            json.put("Rect", WarningresultpersonEntity.getRect());
            json.put("RegionName", WarningresultpersonEntity.getRegionname());
            json.put("Sex", WarningresultpersonEntity.getSex());
            json.put("Time", WarningresultpersonEntity.getTime());
            json.put("Type", WarningresultpersonEntity.getType());
            json.put("DeviceId", WarningresultpersonEntity.getDeviceid());
        }
        return json;
    }

    public boolean isExist(String value){
        return value != null && !value.equals("") ;
    }

    public boolean isInteger(String str) {
        Pattern pattern = Pattern.compile("^[-+]?[\\d]*$");
        return pattern.matcher(str).matches();
    }
}